class DeviceController < ApplicationController
  before_action do
    @user = Rails.cache.fetch(request.headers["token"])
    render json: Failure.new("您还未登录") if @user.blank?
  end

  def update
    if @user.update(update_device_params)
      render json: Success.new
    else
      render json: Failure.new(@user.errors.full_messages)
    end
  end

  protected
  def update_device_params
    params.permit(:device_type, :device_token)
  end
end
